Skip Headers

Oracle® Objects for OLE C++ Class Library Developer's Guide 10g Release 2 (10.2) Part Number B14308-01 |
Home | Book List | Contents | Index | Master Index | Feedback

# ODatabase

A database object represents an Oracle database. If more than one database is opened on a single session with the same database name and connect information (username and password), those database objects share a connection (see OConnection).

Use ODatabase to log on to an Oracle database. You can then execute SQL statements directly with the ExecuteSQL method or you can get records from the Oracle database by using the ODatabase object to create ODynaset objects (see ODynaset). ODatabase is a subclass of OOracleObject.

Four options are available for the ODatabase at the time it is opened. These options are ORed together on the Open method call. They affect operations on dynasets attached to this database. The options are:

Option | Description
--- | ---
ODATABASE_ORAMODE | Turn on requerying on insert
ODATABASE_EDIT_NOWAIT | Turn on no-waiting on StartEdit calls
ODATABASE_NO_REFETCH | Let Oracle set default field (column) values as with ODATABASE_ORAMODE, but data is not refetched after the insert or update operation.
ODATABASE_NONBLOCK | Turn on Non Blocking mode on sql statement execution.
ODATABASE_DEFAULT | Accept the default behavior.

By default these options are off.

ODATABASE_ORAMODE affects the way that AddNew, Edit, and Update put values into the Oracle database and how they change the values of the local data cache. (See ODynaset for a description of the local data cache.) The "partial insert" option of the database affects all dynasets that are created on the database.

If ODATABASE_ORAMODE is off (the default), dynasets behave the way they do in Visual Basic:

- When adding a new record, all fields that were selected to create the dynaset are inserted into the Oracle database. Fields that have not been explicitly set by the user are set to NULL. Any fields that are actually in the table, but do not appear in the dynaset, are set to the default values that Oracle would use for the column.
- When updating a record, only fields that have been modified are updated. The local cache is set to the values that have been inserted into the Oracle database.
- For both adding and updating, the local data cache is set to the values inserted into the Oracle database (including the NULLs).

If ODATABASE_ORAMODE is on, dynasets will behave slightly differently:

- When adding new records, only fields that are NOT NULL are inserted into the Oracle database.
- After adding a new record or updating an existing record, the local cache is set by requerying the Oracle database for that record after the add or update. This allows the Oracle database to set values for fields, perhaps by way of database triggers (which are a kind of stored procedure).

If you are accessing tables that have default values for their fields, or that have triggers that set values on Insert or Update, then you will probably want to user the ODATABASE_ORAMODE option. This will cause the dynaset to refetch records after it makes changes to the data, ensuring that the dynaset and the database will always agree on the record's data. Please see StartEdit for more information.

ODATABASE_EDIT_NOWAIT affects what happens when ODynaset::StartEdit method is called. When StartEdit is called, the dynaset attempts to obtain a lock on the record that is being edited. (See "Locks and Editing"). It also affects ExecuteSQL when the SQL statement being executed performs inserts, updates, or deletes.

- If ODATABASE_EDIT_NOWAIT is off and some other user has a lock on the record, your process waits until the lock is removed. This results in possible deadlock if the caller of StartEdit has outstanding locks that are in turn holding up the user with a lock on the record you want now.
- If ODATABASE_EDIT_NOWAIT is on and another user has a lock on the record, the StartEdit call fails. It is up to the caller to handle the failure properly.

ODATABASE_NO_REFETCH is same as ODATABASE_ORAMODE for setting default values to the fields (columns) by Oracle. However, the data is not refetched to the local cache, boosting performance.

ODATABASE_NONBLOCK executes SQL statement in Non Blocking mode. This mode is not available under 32-bit platform.

The ODatabase class supports the following methods:

Construction and destruction:

ODatabase

~ODatabase

operator=

Attributes:

operator==
operator!=
IsOpen
GetAutoCommit
GetConnectString
GetConnectionOK
GetName
GetOptions
SetAutoCommit
SetCacheMaximumSize
SetCacheOptimalSize
Operations:

BeginTrans
Close
CommitTrans
Describe
ExecuteSQL
GetConnection
GetParameters
GetRowsProcessed
GetSession
Open
RemoveFromPool
Rollback
Error Handling:

ErrorNumber
ErrorReset
GetErrorText
GetServerErrorText
LookupErrorText
ServerErrorNumber
ServerErrorReset
ServerErrorSQLPos